package com.dap.service.impl;

import com.dap.service.ApplicationService;
import com.dap.utils.RedisUtils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import redis.clients.jedis.Jedis;

import java.util.*;

@Service
public class ApplicationServiceImpl implements ApplicationService {

    @Autowired
    private RedisTemplate redisTemplate;


    //获取应用列表
    @Override
    public List<String> getApplicationList() {
        System.out.println("我被访问了");
        List<String> applicationList = new ArrayList<>();
        Set keys = redisTemplate.keys("FOP:Application:" + "*");
        Iterator iterator = keys.iterator();
        while (iterator.hasNext()){
            applicationList.add((String) iterator.next());
        }
        return applicationList;
    }


    //获取某个应用下的服务列表
    @Override
    public List<String> getInterfaceNameList(String applicationName) {
        List<String> interfaceList = new ArrayList<>();
        Set keys = redisTemplate.keys("FOP:Application:" + applicationName + "/" + "*");
        Iterator iterator = keys.iterator();
        while (iterator.hasNext()){
            interfaceList.add((String) iterator.next());
        }
        return interfaceList;
    }


    @Override
    public List<String> getGroupList(String applicationName,String interfaceName) {
        List<String> groupList = new ArrayList<>();
        Set keys = redisTemplate.keys("FOP:Application:" + applicationName + "/Interface:"+interfaceName+"/Group:"+"*");
        Iterator iterator = keys.iterator();
        while (iterator.hasNext()){
            groupList.add((String) iterator.next());
        }
        return groupList;
    }




    @Override
    public String getStutas() {

        return null;
    }

    @Override
    public String changeStutas() {

        return null;
    }

    @Override
    public Boolean isMock() {
        return null;
    }

    @Override
    public Boolean isHystrix() {
        return null;
    }

    @Override
    public Boolean isFlowControl() {
        return null;
    }

    @Override
    public Set<String> ips() {
        return null;
    }
}
